(A) The magnetic field of a dipole $\vec{M} = M\hat{k}$ at a point $(r, \theta)$ in spherical coordinates is given by $\vec{B} = \frac{\mu_0}{4\pi} \frac{M}{r^3} (2\cos\theta \hat{r} + \sin\theta \hat{\theta})$.
$1$. Along the $z$-axis ($P$ to $Q$): $\theta = 0$,$\vec{B} = \frac{\mu_0}{4\pi} \frac{2M}{z^3} \hat{k}$. Thus,$\int_P^Q \vec{B} \cdot d\vec{l} = \int_a^R \frac{\mu_0}{4\pi} \frac{2M}{z^3} dz = \frac{\mu_0 M}{4\pi} [-\frac{1}{z^2}]_a^R = \frac{\mu_0 M}{4\pi} (\frac{1}{a^2} - \frac{1}{R^2})$.
$2$. Along the arc of radius $R$ ($Q$ to $S$): $\vec{B} \cdot d\vec{l} = B_\theta (R d\theta) = \frac{\mu_0}{4\pi} \frac{M}{R^3} \sin\theta (R d\theta) = \frac{\mu_0 M}{4\pi R^2} \sin\theta d\theta$. Integrating from $\theta = 0$ to $\pi/2$: $\int_0^{\pi/2} \frac{\mu_0 M}{4\pi R^2} \sin\theta d\theta = \frac{\mu_0 M}{4\pi R^2} [-\cos\theta]_0^{\pi/2} = \frac{\mu_0 M}{4\pi R^2}$.
$3$. Along the $x$-axis ($S$ to $T$): $\theta = \pi/2$,$\vec{B} = \frac{\mu_0}{4\pi} \frac{M}{x^3} \hat{\theta} = -\frac{\mu_0}{4\pi} \frac{M}{x^3} \hat{k}$. Thus,$\int_S^T \vec{B} \cdot d\vec{l} = \int_R^a (-\frac{\mu_0 M}{4\pi x^3}) dx = \frac{\mu_0 M}{4\pi} [-\frac{1}{2x^2}]_R^a = -\frac{\mu_0 M}{8\pi} (\frac{1}{a^2} - \frac{1}{R^2})$.
$4$. Along the arc of radius $a$ ($T$ to $P$): $\vec{B} \cdot d\vec{l} = \frac{\mu_0 M}{4\pi a^2} \sin\theta d\theta$. Integrating from $\pi/2$ to $0$: $\int_{\pi/2}^0 \frac{\mu_0 M}{4\pi a^2} \sin\theta d\theta = -\frac{\mu_0 M}{4\pi a^2}$.
Summing these,$\oint \vec{B} \cdot d\vec{l} = 0$,which verifies Ampere's law for this path as there is no current enclosed.